{include file="public/nheader" /}
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="用户名|身份证|手机号" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="status">
                                <option value="">状态</option>
                                <option value="1" {if !empty(input('get.status')) &&
                                    input('get.status')==1}selected{/if}>待审核</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>已打款</option>
                                <option value="3" {if !empty(input('get.status')) &&
                                    input('get.status')==3}selected{/if}>驳回申请</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="agentid" lay-filter="agentid" lay-search>
                                <option value="">选择代理商</option>
                                {foreach $agent as $v}
                                <option value="{$v.id}" {if !empty(input('get.agentid')) &&
                                    input('get.agentid')==$v.id}selected{/if}>{$v.nickname}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card-header layadmin-card-header-auto" style="color: red;">
            请先进行打款按钮操作后再进行转账，避免转账过程中代理取消提现造成余额原路反还并且线下已转账的重复操作。
        </div>
        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    {{#  if(d.status ==1){ }}
    {{#  if(d.type ==1){ }}
    <a class="layui-table-text" data-url="/agent/withdraw_status?id={{d.id}}&status=2" data-confirm="请确认后并进行打款" lay-ajax="" data-reload="self">打款</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text layui-color-red" data-title="驳回" data-area="30%,40%" callback="edits" data-url="#adminforms"  lay-event="edit">驳回</a>
    <div class="layui-divider layui-divider-vertical"></div>
    {{#  } }}
    {{#  if(d.type ==2){ }}
    <span class="layui-badge layui-bg-orange">自动转账中</span>
    {{#  } }}
    {{# }if(d.status ==2) { }}
    <span class="layui-badge layui-bg-orange">已打款</span>
    {{# }if(d.status ==3) { }}
    <span class="layui-badge layui-bg-green">已驳回</span>
    {{#  } }}
</script>
<script type="text/html" id="adminforms">
    <div class="layui-fluid layui-bg-white">
        <form class="layui-form layui-form-fixed" lay-filter="adminforms">
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>驳回理由</label>
            <div class="layui-input-block">
                <input name="text"  placeholder="请填写驳回理由" type="text" class="layui-input" lay-verify="required" />
            </div>
        </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn" lay-filter="submitPage" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >取消</button>
        </div>
        </form>
    </div>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form'], function () {

        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form;
        /*
         * 初始化表格
        */
        admin.callback.edits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {

                // 获取用户id
                var pageThat = layui.$(this);
                pageThat.attr("disabled", true);
                // 开始POST提交数据
                post.field.id = tableThis.data.id;
                post.field.status = 3;
                layui.$.post("{:url('agent/withdraw_status')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                    }
                    else {
                        layer.error(res.msg);
                    }
                }, 'json');

                return false;
            })
        }
        var isTable = table.render({
            elem: "#lay-tableList",
            where: {
                agentid: "{:input('agentid/d',0)}"
            }
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true
            , toolbar: 'true'
            , defaultToolbar: ['filter', 'print', 'exports']
            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { field: 'agent_name', width: 150, align: 'center', title: '代理商' },
                {
                    field: 'bank', width: 200, align: 'center', title: '开户行', templet: function (d) {
                        if (d.type == 2) {
                            return '<button class="layui-btn icon-btn layui-bg-cyan">' + d.bank + '</button>';
                        }
                        return '<button class="layui-btn icon-btn">' + d.bank + '</button>';
                    }
                }, { field: 'name', align: 'center', width: 120, title: '开户名' },
                {
                    field: 'cards', width: 200, align: 'center', title: '卡号', templet: function (d) {
                        if (d.type == 2) {
                            return '微信转账';
                        }
                        return d.cards;
                    }
                }, { field: 'bank', width: 150, align: 'center', title: '开户行' },
                {
                    field: 'money', align: 'center', width: 120, templet: function (d) {
                        return '<a style="color:blue" class="layui-table-text" lay-open data-title="订单记录" data-area="90%,90%" data-url="/agent/agentlog?agentid=' + d.user_id + '" >' + d.money + '</a>';
                    }, title: '提现金额'
                },
                { field: 'fee', width: 150, align: 'center', title: '手续费' },
                {
                    field: 'sk', align: 'center', width: 120, templet: function (d) {
                        return (d.money - d.fee).toFixed(2);
                    }, title: '实际需打款'
                },
                {
                    field: 'status', align: 'center', width: 120, templet: function (d) {
                        var text = '';
                        if (d.status == 1) {
                            text = '<span class="layui-badge layui-bg-blue">待审核</span>';
                        }
                        if (d.status == 2) {
                            text = '<span class="layui-badge layui-bg-orange">已打款</span>';
                        }
                        if (d.status == 3) {
                            text = '<span class="layui-badge layui-bg-green">已驳回</span>';
                        }
                        return text;
                    }, title: '类型'
                },
                {
                    field: 'text', width: 150, align: 'center', title: '驳回理由', templet: function (d) {
                        if (!d.text) {
                            return text = '无';
                        }
                        return d.text;
                    }
                },
                { field: 'created', width: 150, align: 'center', title: '提交时间' },
                { align: 'center', toolbar: '#tableBar', width: 200, title: '操作' },
            ]]
        })
    })
</script>
</body>